package com.gxsf.back.controller;

import com.gxsf.back.pojo.Admin;
import com.gxsf.back.repo.AdminRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author BeijiRonin
 * @date 2020/11/12
 */
@CrossOrigin
@RestController
@RequestMapping("/admin_json")
@Slf4j
@Api(value = "管理员接口", tags = "类似用户接口的user_json")
public class AdminController {
    @Autowired
    AdminRepository adminRepository;
    @PostMapping("/login")
    @ApiOperation("登录,参数传name和password")
    @ResponseBody
    public Admin login(@RequestBody Map<String, String> map) {
        String name = map.get("name");
        String password = map.get("password");
//        return userService.login(name, password);
        Admin admin = adminRepository.findFirst1ByNameAndPassword(name, password);
        return admin;
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public Admin add(String name, String password) {
        return adminRepository.findFirst1ByNameAndPassword(name, password);
    }
}
